package com.bqtt.tumor.demo.business;

import java.util.List;

import org.tbwork.utility.toolbox.tbEncode;

import com.bqtt.tumor.demo.common.MyBeanFactory;
import com.bqtt.tumor.demo.data_access.SystemUserDAO;
import com.bqtt.tumor.demo.entity.SystemUser;
public class UserService {

	
	private static SystemUserDAO userDAO = (SystemUserDAO) MyBeanFactory.getBean("systemUserDAO");
	
	
	
	/**
	 * @param user
	 * @return 0-不存在  1-系统管理员  2-注册管理员 3-支持数据管理员 4-病例数据管理员 5-医生/医师 6-病人
	 */
	public static int userAuthentication(SystemUser user)
	{
		
		user.setUsername_md5(tbEncode.MD5(user.getUsername()));
		List loadFromDB = (List) userDAO.findByProperty("username_md5", user.getUsername_md5());
		
		// 判空
		if(loadFromDB==null || loadFromDB.size()==0)
		{
			return 0;
		}
		
		SystemUser userInDB = (SystemUser) loadFromDB.get(0);
		if(userInDB!=null)
		{
			if(user.getPassword().equals(userInDB.getPassword()))
			{//密码相同则通过认证
				int privilege = userInDB.getPrivilege();
				return privilege;
			}
		}
		
		return 0;
	}
	
	
	public static void saveToSession(SystemUser user)
	{
		
	}
	
}
